package com.vincent.sciinfo.service.impl;

import com.vincent.sciinfo.mapper.TeacherMapper;
import com.vincent.sciinfo.pojo.Teacher;
import com.vincent.sciinfo.pojo.TeacherExample;
import com.vincent.sciinfo.pojo.User;
import com.vincent.sciinfo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;


    @Override
    public List<Teacher> selectTeacherById(String userId) {
        TeacherExample teacherExample = new TeacherExample();
        TeacherExample.Criteria criteria = teacherExample.createCriteria();
        criteria.andTeacheridEqualTo(userId);
        return teacherMapper.selectByExample(teacherExample);
    }

    @Override
    public void updateTeacher(Teacher teacher) {
        teacherMapper.updateByPrimaryKeySelective(teacher);
    }

    @Override
    public int updateTeacherMeetingById(String teacher_id, int newMeetingId) {
        return 0;
    }

    @Override
    public List<Teacher> getNameByMeetingId(int meetingid) {
        return null;
    }

    /**
     * 添加一名教师，同时开通登陆系统权限
     */
    @Override
    public int insertTeacher(Teacher teacher) {
        return teacherMapper.insert(teacher);
    }

    @Override
    public List<Teacher> selectAllTeacher() {
        return teacherMapper.selectByExample(null);
    }

    @Override
    public int updateTeacher(String teacherId, int opeaCode) {
        int ret;
        List<Teacher> teacher;
        TeacherExample teacherExample = new TeacherExample();
        TeacherExample.Criteria criteria = teacherExample.createCriteria();
        List<String> idList = new LinkedList<>();
        idList.add(teacherId);
        criteria.andTeacheridIn(idList);
        teacher = teacherMapper.selectByExample(teacherExample);
        teacher.get(0).setTeacherstatu(opeaCode);
        ret = teacherMapper.updateByPrimaryKey(teacher.get(0));
        return ret;
    }

    @Override
    public List<Teacher> selectTeacherNotLogOut(int status) {
        return teacherMapper.selectByStatus(status);
    }

}
